home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10519 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  37 lines

  1. Path: ppp58.micronet.fr!user
  2. From: fgrieu@micronet.fr (Franτois Grieu)
  3. Newsgroups: comp.arch.arithmetic,comp.lang.c,comp.lang.c++
  4. Subject: Re: Access carry flag from C
  5. Date: Fri, 08 Mar 1996 14:32:57 +0100
  6. Organization: Innovatron
  7. Message-ID: <fgrieu-0803961432570001@ppp58.micronet.fr>
  8. References: <Dn1C9z.DGv.0.net@indra.com> <825377932snz@genesis.demon.co.uk> <4h1veoINNlns@anvil.ugrad.cs.ubc.ca> <fgrieu-0403961143580001@ppp78.micronet.fr> <4hhbt8$1d3o@b.stat.purdue.edu>
  9. NNTP-Posting-Host: ppp58.micronet.fr
  10. X-Newsreader: Yet Another NewsWatcher 2.1.2
  11.  
  12. In article <4hhbt8$1d3o@b.stat.purdue.edu>, hrubin@b.stat.purdue.edu
  13. (Herman Rubin) wrote:
  14.  
  15. > Notice that in (original code: fgrieu-0403961143580001@ppp78.micronet.fr)
  16. > each addition must be performed twice.
  17.  
  18.  
  19. Silly of me.  This extra addition can be avoided entirely, as well as
  20. any temporary variable.  The following, improved trick should works just as
  21. fine, for the purprose of doing multiple precision addition in a quite
  22. portable  manner.
  23.  
  24.  
  25. unsigned long yl,yh;  /* double_unsigned_long_int y */
  26. unsigned long x;
  27.  
  28. /* add x to double_unsigned_long_int y */
  29.    yl += x;
  30.    if (yl < x) ++yh;  /* test if overflow occured on previous line */
  31.  
  32. the adventurous can even try
  33.    if ((yl += x) < x) ++yh;  /* add x to double_unsigned_long_int y */
  34.  
  35. -- 
  36. Francois Grieu                               email:fgrieu@micronet.fr
  37.